﻿/*
CLUDG Functions
*/

function setCommentForm(blockId) {
	var block = $("#replay_0");
	if (blockId != null) {
		block = $("#replay_" + blockId);
	}
	if (block != null) {
		var commentForm = $("#commentForm");
		// Hide other comment forms
		$(".replayCommentForm").html("");
		// Copy form to comment block
		block.html("<div class='replayCommentForm'>" + commentForm.html() + "</div>");
		// add commentId to action
		if (blockId != null) {
			block.find("#CommentId").attr("value", blockId);
		}
		// set focus to input
		block.find("#CommentBody").focus();
		validateCommentForm();
	}
}

function getParameterByName(queryString, paramName) {
	paramName = paramName.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + paramName + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(queryString);
	if (results == null)
		return "";
	else
		return results[1];
}

/* Story/Show.aspx */
function improveComments() {
	// modify all reply objects to show form for replys on story page
	$(".reply")
		.queue(function () {
			var commentId = getParameterByName(this, "commentId");
			//alert(commentId);
			$(this).click(function () {
				setCommentForm(commentId);
				return false;
			});
			$(this).attr("href", "#comment_" + commentId);
			$(this).dequeue();
		});
}

function validateCommentForm() {
	$("#commentSubmitForm").validate({
		rules: {
			CommentBody: "required"
		},
		messages: {
			CommentBody: "Комментарий не может быть пустым."
		},
		wrapper: "div"
	});
}

/* AlertControl.ascx */
function animateCloseMessageBox() {
	//      	$("#closeMsgBox").click(
	//          function () {
	//          	$("#msgBoxContainer")
	//			.animate({ height: "hide" }, "slow");
	//          }
	//        );
	$("#msgBoxContainer")
	.animate({ opacity: 1.0 }, 3000)
	.animate({ height: "hide" }, "slow")
}
